import {
  Entity,
  Column,
  PrimaryGeneratedColumn,
  ManyToOne,
  PrimaryColumn,
} from 'typeorm';
import { Singer } from './singer.entity';
import { ApiProperty } from '@nestjs/swagger';
import { BaseEntity } from './base.entity';
import * as crypto from 'crypto';
import { Transform } from 'class-transformer';
import { User } from './user.entity';
@Entity()
export class CommentSinger extends BaseEntity {
  constructor() {
    super();
    this.id = crypto.randomBytes(8).toString('hex'); // 生成一个8字节（16个十六进制字符）的随机字符串作为id
  }
  @ApiProperty({
    required: false,
    description: '评论id',
  })
  @PrimaryColumn({ length: 225 })
  id: string;

  @ApiProperty({
    required: false,
    description: '评论内容',
  })
  @Column({ type: 'varchar', length: 255, comment: '评论内容' })
  content: string;

  @ApiProperty({
    required: false,

    description: '是否已审批',
  })
  @Column({
    type: 'varchar',
    comment: '是否已审批0显示1禁用',
    default: '0',
  })
  @Transform(({ value }) => value === 0)
  approved: string;

  @ManyToOne(() => Singer, (singer) => singer.comments, {

    onDelete: 'CASCADE',
  })
  singer: Singer;

  @ManyToOne(() => User, (user) => user.voteRecords, {

    onDelete: 'CASCADE',
  })
  user: User;

  @Column()
  userId: string; // 将用户ID作为外键存储

  @Column()
  singerId: string; // 将歌手ID作为外键存储
}
